//
//  MainTabBar.swift
//  sina
//
//  Created by lixuelei on 5/10/15.
//  Copyright © 2015 itcast. All rights reserved.
//

import UIKit

class MainTabBar: UITabBar {

   //改变布局tabBarItem位置 大小
    override func layoutSubviews() {
        super.layoutSubviews()
        
        //定义一个index
        var index: CGFloat = 0
        //定义一个frame
        let w = UIScreen.mainScreen().bounds.width / 5
        let h = self.bounds.height
        let frame = CGRectMake(0, 0, w, h)
        
        for view in subviews{
            if view is UIControl && !(view is UIButton){
            view.frame = CGRectOffset(frame, index * w, 0)
                if index == 1{
                    index++
                }
            
                index++
            }
        }
        composeButton.frame = CGRectOffset(frame, 2 * w, 0)
    }
    
    
    //懒加载的到一个按钮
    lazy var composeButton: UIButton = {
        //button的类型
        let btn = UIButton(type: UIButtonType.Custom)
        
        btn.setBackgroundImage(UIImage(named: "tabbar_compose_button"), forState: UIControlState.Normal)
        btn.setImage(UIImage(named: "tabbar_compose_icon_add"), forState: UIControlState.Normal)
        btn.setBackgroundImage(UIImage(named: "tabbar_compose_button_highlighted"), forState: UIControlState.Highlighted)
        btn.setImage(UIImage(named: "tabbar_compose_icon_add_highlighted"), forState: UIControlState.Normal)
        
        self.addSubview(btn)
    
    return btn
    }()
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
}
